package com.guigu.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.guigu.dao.EvaluationSuggestionsMapper;
import com.guigu.entity.PageResult;
import com.guigu.pojo.EvaluationSuggestions;
import org.springframework.beans.factory.annotation.Autowired;

@Service(interfaceClass= EvaluationSuggestionsService.class)
public class EvaluationSuggestionsServiceImpl implements EvaluationSuggestionsService {
    @Autowired
    private EvaluationSuggestionsMapper suggestionsMapper;

    /**
     * 在EvaluationSuggestionsService服务接口中扩展分页查询方法
     *
     * @param currentPage
     * @param pageSize
     * @param queryString
     * @return
     */
    @Override
    public PageResult pageQuery(Integer currentPage, Integer pageSize, String queryString) {
        PageHelper.startPage(currentPage,pageSize);
        Page<EvaluationSuggestions> page=suggestionsMapper.selectByCondition(queryString);
        return new PageResult(page.getTotal(),page.getResult());
    }

    /**
     * 根据id进行查询
     *
     * @param id
     * @return
     */
    @Override
    public EvaluationSuggestions findById(Integer id) {
        return suggestionsMapper.selectByPrimaryKey(id);
    }

    /**
     * 添加数据
     *
     * @param eval
     * @return
     */
    @Override
    public boolean add(EvaluationSuggestions eval) {
        boolean flag=false;
        int i = suggestionsMapper.insertSelective(eval);
        if (i>0){
            flag=true;
        }

        return flag;
    }

    /**
     * 根据EvaluationSuggestions修改数据
     *
     * @param eval
     * @return
     */
    @Override
    public boolean edit(EvaluationSuggestions eval) {
        int i = suggestionsMapper.edit(eval);
        if(i>0){
            return true;
        }
        return false;
    }

    /**
     * 根据id删除数据
     *
     * @param id
     * @return
     */
    @Override
    public boolean delById(Integer id) {
        boolean flag=false;
        //给条件(id)
        EvaluationSuggestions eval=new EvaluationSuggestions();
        eval.setId(id);
        eval.setIsDel("1");
        int i = suggestionsMapper.updateByPrimaryKeySelective(eval);

        if (i>0){
            flag=true;
        }

        return flag;
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Override
    public EvaluationSuggestions selectById(Integer id) {
        return suggestionsMapper.selectByPrimaryKey(id);
    }
}
